<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\time_slot;
use App\Models\data_time;
use App\Models\med_doctor;
//排班表
class doctor_work extends Model
{
    use HasFactory;
    protected $table='med_doctor_work';
    protected $primaryKey='id';
    protected $fillable=['doctor_id','time_up_id','time_this_id','time_down_id','office_id'];

    public function time_this_slot()
    {
        return $this->hasMany(time_slot::class,'time_id','time_this_id');
    }
    public function time_up_slot()
    {
        return $this->hasMany(time_slot::class,'time_id','time_up_id');
    }
    public function time_down_slot()
    {
        return $this->hasMany(time_slot::class,'time_id','time_down_id');
    }

    public function doctor()
    {
        return $this->hasMany(med_doctor::class,'id','doctor_id')->select('id','doctor_name','office_id');
    }

    public function show($time)
    {
        return self::with([$time,'doctor','doctor.office',
            "$time.one_up","$time.two_up","$time.three_up","$time.four_up","$time.five_up","$time.six_up","$time.seven_up",
            "$time.one_down","$time.two_down","$time.three_down","$time.four_down","$time.five_down","$time.six_down","$time.seven_down"
        ])->get();
//        return self::with([function()use($time){3
//            $this->time_slot($time);
//        },'doctor','doctor.office',
//            'time_slot.one_up','time_slot.two_up','time_slot.three_up','time_slot.four_up','time_slot.five_up','time_slot.six_up','time_slot.seven_up',
//            'time_slot.one_down','time_slot.two_down','time_slot.three_down','time_slot.four_down','time_slot.five_down','time_slot.six_down','time_slot.seven_down'
//        ])->get();
    }

}
